package com.youku.plugins.report.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.plugins.report.model.ReportProxy;
   import com.youku.events.PlayerControlEvent;
   import com.youku.events.PluginEvent;
   import com.youku.PlayerConfig;
   import com.youku.events.ConductorEvent;
   import com.youku.events.ReportEvent;
   import com.youku.P2PConfig;
   
   public class ReportMediator extends Object
   {
      
      public function ReportMediator(param1:MovieClip, param2:IPlayerProxy, param3:ReportProxy) {
         super();
         this._mainMc = param1;
         this._playerProxy = param2;
         this._reportProxy = param3;
         this.init();
         if(!PlayerConfig.isTudouPlayer)
         {
            this.initIR();
         }
      }
      
      private var _mainMc:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _reportProxy:ReportProxy;
      
      private var _IRCookie:FlashCookie;
      
      private function initIR() : void {
         this._IRCookie = new FlashCookie();
         this._IRCookie._IWT_UAID = "UA-youku-100008";
         if(this._playerProxy.rootGetData.rootWinType == "interior" || this._playerProxy.rootGetData.rootWinType == "index" || this._playerProxy.rootGetData.rootWinType == "adshow" || this._playerProxy.rootGetData.rootWinType == "popup" || this._playerProxy.rootGetData.rootWinType == "touch")
         {
            this._IRCookie._IWT_UAID = "UA-youku-100009";
         }
         else if(this._playerProxy.rootGetData.rootWinType == "exterior")
         {
            this._IRCookie._IWT_UAID = "UA-youku-100008";
         }
         else if(this._playerProxy.rootGetData.rootWinType == "BDskin")
         {
            this._IRCookie._IWT_UAID = "UA-youku-100007";
         }
         else if(this._playerProxy.rootGetData.rootWinType == "ikupartner")
         {
            this._IRCookie._IWT_UAID = "UA-youku-130001";
         }
         
         
         
         this._playerProxy.addEventListener(PlayerControlEvent.VIDEO_START_TO_PLAY,this.onVideoStartToPlay);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_PAUSE,this.onPause);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_RESUME,this.onResume);
         this._playerProxy.addEventListener(PlayerControlEvent.CORE_TOGGLE_PAUSEPLAY,this.onPausePlay);
         this._playerProxy.addEventListener(PlayerControlEvent.VIDEO_END,this.onVideoEnd);
         this._playerProxy.addEventListener(PlayerControlEvent.ENDCARD_REPLAY,this.onVideoReplay);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_DRAG_FINISH,this.onSeek);
         this._playerProxy.addEventListener(PluginEvent.CONTROL_BAR_SEEK,this.onSeek);
      }
      
      private function onResume(param1:PlayerControlEvent) : void {
         this._IRCookie.IRS_UserACT("play");
      }
      
      private function onPause(param1:PlayerControlEvent) : void {
         if((param1.data) && (param1.data.hasOwnProperty("useraction")))
         {
            if(param1.data.useraction == true)
            {
               this._IRCookie.IRS_UserACT("pause");
            }
         }
      }
      
      private function onVideoStartToPlay(param1:PlayerControlEvent) : void {
         if(this._IRCookie == null)
         {
            return;
         }
         this._IRCookie.IRS_NewPlay(this._playerProxy.playerData.videoIdEncode,int(this._playerProxy.playerData.videoTotalTime),true);
         this._IRCookie.IRS_UserACT("play");
         if(!(PlayerConfig.partnerData == null) && PlayerConfig.partnerData.status == 1 && !(PlayerConfig.partnerData.token == null) && !(PlayerConfig.partnerData.token == ""))
         {
            this._reportProxy.sendPartnerConsume(PlayerConfig.partnerData.token);
         }
      }
      
      private function onSeek(param1:PluginEvent) : void {
         this._IRCookie.IRS_UserACT("drag");
      }
      
      private function onPausePlay(param1:PlayerControlEvent) : void {
         if(this._playerProxy.playerData.videoIsPause)
         {
            this._IRCookie.IRS_UserACT("play");
         }
         else
         {
            this._IRCookie.IRS_UserACT("pause");
         }
      }
      
      private function onVideoEnd(param1:PlayerControlEvent) : void {
         this._IRCookie.IRS_UserACT("end");
      }
      
      private function onVideoReplay(param1:PlayerControlEvent) : void {
         this._IRCookie.IRS_NewPlay(this._playerProxy.playerData.videoIdEncode,int(this._playerProxy.playerData.videoTotalTime),true);
      }
      
      protected function get reportProxy() : ReportProxy {
         return this._reportProxy;
      }
      
      private function init() : void {
         this._playerProxy.addEventListener(ConductorEvent.METADATA_UPDATED,this.onMetadataUpdated);
         this._playerProxy.addEventListener(ReportEvent.USERACTION_REPORT,this.onUserActionEvent);
         this._playerProxy.addEventListener(ReportEvent.STATIC_REPORT,this.onStaticReport);
         this._playerProxy.addEventListener(ReportEvent.DYNAMIC_REPORT,this.onDynamicReport);
         this._playerProxy.addEventListener(ReportEvent.WASTE_REPORT,this.onWasteReport);
         this._playerProxy.addEventListener(ReportEvent.VIDEO_TIME_REPORT,this.onVideoTimeReport);
         this._playerProxy.addEventListener(ReportEvent.WPLAY_LOG_REPORT,this.onWplayLogReport);
         this._playerProxy.addEventListener(ReportEvent.FULLSCREEN_REPORT,this.onFullScreenReport);
         this._playerProxy.addEventListener(ReportEvent.REPLAY_REPORT,this.onReplayReport);
         this._playerProxy.addEventListener(ReportEvent.EXTERIOR_REPORT,this.onExteriorReport);
         this._playerProxy.addEventListener(ReportEvent.AD_BLOCK_NOTICE_REPORT,this.onADBlockNotice);
         this._playerProxy.addEventListener(ReportEvent.ENDCARD_RELATED_REPORT,this.onEndcardReport);
         this._playerProxy.addEventListener(ReportEvent.DELAY_TIME_REPORT,this.onDelayTimeReport);
         this._playerProxy.addEventListener(ReportEvent.JUMP_URL_ERROR,this.onJumpURLError);
         this._playerProxy.addEventListener(ReportEvent.INVALID_PLAY_EVENT,this.onInvalidPlayEvent);
         this._playerProxy.addEventListener(ReportEvent.PLAY_POLICY_ALLOW,this.onPlayVV);
         this._playerProxy.addEventListener(ReportEvent.PLAYVV_IKU,this.onPlayVV);
         this._playerProxy.addEventListener(ReportEvent.LOAD_P2P_SWC,this.onPlayVV);
         this._playerProxy.addEventListener(ReportEvent.CORE_INIT_EVENT,this.onPlayVV);
         this._playerProxy.addEventListener(ReportEvent.NOT_REAL_USE_P2P,this.onPlayVV);
         this._playerProxy.addEventListener(ReportEvent.REAL_USE_P2P,this.onPlayVV);
         this._playerProxy.addEventListener(ReportEvent.P2P_SOCKET_FAIL,this.onPlayVV);
         this._playerProxy.addEventListener(ReportEvent.PLAY_ERROR,this.onPlayError);
         this._playerProxy.addEventListener(ReportEvent.PLAYER_LOAD_TIME_EVENT,this.onPlayerLoadTimeEvent);
         this._playerProxy.addEventListener(ReportEvent.LOAD_TIME_REPORT,this.onLoadTimeReportEvent);
         this._playerProxy.addEventListener(ReportEvent.AD_BLOCK_REPORT,this.onADBlockReport);
      }
      
      private function onEndcardReport(param1:ReportEvent) : void {
         this.reportProxy.sendEndcardLog(param1.data as String);
      }
      
      private function onMetadataUpdated(param1:ConductorEvent) : void {
         this.reportProxy.createReportData();
      }
      
      private function onStaticReport(param1:ReportEvent) : void {
         this.reportProxy.addPlayerStaticReport();
      }
      
      private function onDynamicReport(param1:ReportEvent) : void {
         var _loc2_:String = param1.data.code;
         var _loc3_:int = param1.data.number;
         this.reportProxy.addPlayerDynamicReport(_loc2_,_loc3_);
      }
      
      private function onWasteReport(param1:ReportEvent) : void {
         var _loc2_:int = param1.data.number;
         this.reportProxy.addWasteReport(_loc2_);
      }
      
      private function onFullScreenReport(param1:ReportEvent) : void {
         this.reportProxy.sendFullScreen();
      }
      
      private function onReplayReport(param1:ReportEvent) : void {
         this.reportProxy.sendReplay();
      }
      
      private function onExteriorReport(param1:ReportEvent) : void {
         var _loc2_:int = param1.data.t;
         var _loc3_:int = param1.data.a;
         this.reportProxy.setlog(_loc2_,_loc3_);
      }
      
      private function onUserActionEvent(param1:ReportEvent) : void {
         var _loc2_:* = "";
         var _loc3_:* = "";
         var _loc4_:Object = null;
         if(param1.data)
         {
            _loc2_ = param1.data.action;
            _loc3_ = param1.data.method;
            _loc4_ = param1.data.data;
         }
         this.reportProxy.sendUserActionLog(_loc2_,_loc3_,_loc4_);
      }
      
      private function onVideoTimeReport(param1:ReportEvent) : void {
         var _loc2_:Object = {};
         _loc2_.times = param1.data.times;
         _loc2_.starttime = 0;
         if(param1.data.starttime)
         {
            _loc2_.starttime = param1.data.starttime;
         }
         this.reportProxy.sendVideoTime(_loc2_);
      }
      
      private function onWplayLogReport(param1:ReportEvent) : void {
         this.reportProxy.sendWplaylog();
      }
      
      private function onADBlockNotice(param1:ReportEvent) : void {
         var _loc2_:String = param1.data.type;
         var _loc3_:Number = param1.data.time;
         var _loc4_:Boolean = param1.data.fa;
         var _loc5_:Number = -1;
         if(!(param1.data.last == undefined) && !(param1.data.last == null))
         {
            _loc5_ = param1.data.last;
         }
         this.reportProxy.sendADBlockNoticeLog(_loc2_,_loc3_,_loc4_,_loc5_);
      }
      
      private function onDelayTimeReport(param1:ReportEvent) : void {
         var _loc2_:Number = param1.data.dt;
         this.reportProxy.sendDelayTimeLog(_loc2_);
      }
      
      private function onInvalidPlayEvent(param1:ReportEvent) : void {
         this.reportProxy.sendInvalidEventReport(param1.data);
      }
      
      private function onPlayVV(param1:ReportEvent) : void {
         if(P2PConfig.isP2PPlayer)
         {
            this.reportProxy.sendPlayVVReport(param1);
         }
      }
      
      private function onPlayError(param1:ReportEvent) : void {
         this.reportProxy.sendPlayErrorReport(param1);
      }
      
      private function onPlayerLoadTimeEvent(param1:ReportEvent) : void {
         this.reportProxy.sendLoadTimeEvent(param1);
      }
      
      private function onLoadTimeReportEvent(param1:ReportEvent) : void {
         try
         {
            this.reportProxy.sendLoadTimeReport(param1.data.isError,param1.data.type,param1.data.errorCode);
         }
         catch(error:Error)
         {
         }
      }
      
      private function onJumpURLError(param1:ReportEvent) : void {
         var _loc2_:String = param1.data as String;
         this.reportProxy.sendJumpUrlErrorLog(_loc2_);
      }
      
      private function onADBlockReport(param1:ReportEvent) : void {
         this.reportProxy.sendADBlockReport(param1.data.st,param1.data.bt);
      }
   }
}
